<template>
  <div class="search">
    <!-- 搜索 -->
    <van-search
      show-action
      v-model="searchtext"
      shape="round"
      background="#fff"
      placeholder="卡姿兰大眼睛"
      :autofocus="true"
      @keydown.stop.enter="search"
    >
      <template #left>
        <div class="address" @click="this.$router.push('/home')">
          <van-icon name="arrow-left" />
        </div>
      </template>
      <template #action>
        <div class="my" @click="search">搜索</div>
      </template>
    </van-search>

    <!-- 列表 -->
    <ul class="list">
      <li
        v-for="item in searchList"
        :key="item"
        v-show="item.img1"
        @click="$router.push(`/details?id=${item.proid}`)"
      >
        <img :src="item.img1" :alt="item.proname" />
        <p>{{ item.proname }}</p>
        <span>￥{{ item.originprice }}</span>
      </li>
    </ul>
    <span class="footer" v-show="!searchList">没有更多</span>
  </div>
</template>

<script>
import { proSearch } from "../server/search.js";
export default {
  data() {
    return {
      searchtext: "",
      searchList: [],
    };
  },
  computed: {
    getList() {
      return this.$store.state.searchList;
    },
  },
  created() {
    this.searchtext = this.$route.query.search;
    this.searchList = this.$store.state.searchList;
  },
  methods: {
    search() {
      if (!this.searchtext) return;
      proSearch({ count: 1, limitNum: 10, keyword: this.searchtext }).then(
        (res) => {
          this.searchList = res.data;
        }
      );
    },
    searchCklick(e) {
      this.searchtext = e.target.innerText;
      this.search();
    },
  },
};
</script>

<style scoped>
.list {
  border-radius: 0.9375rem;
  padding: 0 0.625rem;
  box-sizing: border-box;
  margin: 0.3125rem 0;
  display: flex;
  flex-wrap: wrap;
  background-color: rgb(246, 246, 246);
  justify-content: space-between;
}
.list > li {
  width: 45%;
  margin: 0.625rem 0.3125rem;
  border-radius: 0.9375rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.list > li > img {
  width: 100%;
  border-radius: 0.9375rem;
}
.list > li > p {
  font-size: 0.75rem;
  color: #666;
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list > li > span {
  color: red;
  text-align: center;
}
.van-cell-group {
  margin-top: 1.25rem;
}
.van-search {
  height: 3.125rem;
  width: 100%;
  padding: 0 0.625rem;
}
.address {
  margin-right: 0.625rem;
}
.my,
.address {
  color: #666;
}
.van-search__content {
  border-radius: 1.875rem;
}

:deep(.van-grid-item__content) {
  padding: 0;
}
.footer {
  display: block;
  font-size: 1rem;
  width: 100%;
  margin-top: 6.25rem;
  text-align: center;
  line-height: 1;
  color: #666;
}
</style>
